package conf

import (
	"fmt"

	"github.com/jinzhu/configor"
)

// configType 中心服务器配置类型
type configType struct {
	DBHostPort    string `yaml:"dbHostPort" required:"true"`
	DBName        string `yaml:"dbName" required:"true"`
	DBUser        string `yaml:"dbUser" required:"true"`
	DBPassword    string `yaml:"dbPassword" required:"true"`
	WebServerPort int    `yaml:"webServerPort" required:"true"`
	User          string `yaml:"user" required:"true"`
	Password      string `yaml:"password" required:"true"`
	AppSecret     string `yaml:"appSecret" required:"true"`
}

// Config 中心服务器配置
var Config = &configType{}

func loadConfig() error {
	if err := configor.New(&configor.Config{ErrorOnUnmatchedKeys: true}).Load(Config, "./config.yml"); err != nil {
		return err
	}
	return nil
}

func init() {
	if err := loadConfig(); err != nil {
		panic(fmt.Sprintf("读取配置失败，错误：%v", err))
	}
}
